package com.example.demolearn.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.net.URLEncoder;

@RestController
@RequestMapping("/export")
public class ExportExcelController {
    @RequestMapping("/excel")
    public void exportExcel(HttpServletResponse response) throws UnsupportedEncodingException {
        FileOutputStream outputStream = null;
        File file = new File("hello.txt");
        String content = "you are mine";
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("somename" +".xls", "utf-8"));
        try {
            ServletOutputStream outputStream1 = response.getOutputStream();
            outputStream1.write(content.getBytes());
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }
    @RequestMapping("/sayHello")
    public String sayHello(@RequestParam("name")String name){
        return "sayHello";
    }
}
